<%= render Settings::H1Component.new do %>
  Account
<% end %>

<%= form_for(@user, html: {class: "mb-14"}) do |f| %>

  <%= render Settings::H2Component.new do %>
    <%= f.label :email, "Email" %>
  <% end %>

  <%= render Form::TextInputComponent.new do |text| %>
    <% text.input do %>
      <%= f.email_field :email, placeholder: "Email", class: "peer text-input" %>
    <% end %>
  <% end %>

  <%= render Settings::ButtonRowComponent.new do %>
    <button type="submit" class="button">Update</button>
  <% end %>
<% end %>

<%= form_for(@user, html: {class: "mb-14"}) do |f| %>
  <%= render Settings::H2Component.new do %>
    Update Password
  <% end %>

  <div class="mb-4">
    <%= render Form::TextInputComponent.new do |text| %>
      <% text.label_content do %>
        <%= f.label :old_password, "Old Password" %>
      <% end %>
      <% text.input do %>
        <%= f.password_field :old_password, class: "peer text-input" %>
      <% end %>
    <% end %>
  </div>

  <%= render Form::TextInputComponent.new do |text| %>
    <% text.label_content do %>
      <%= f.label :password, "New Password" %>
    <% end %>
    <% text.input do %>
      <%= f.password_field :password, class: "peer text-input" %>
    <% end %>
  <% end %>


  <%= render Settings::ButtonRowComponent.new do %>
    <button type="submit" class="button">Update</button>
  <% end %>
<% end %>

<%= form_for(@user, method: :delete, id: "delete_user", html: {class: "mb-14"}) do |f| %>
  <%= render Settings::H2Component.new do %>
    Cancel Account
  <% end %>

  <p class="mb-4">Canceling your account will end your subscription immediately. All of your data will be deleted. You will receive a confirmation email with your feed subscriptions attached. <strong>You cannot undo this</strong>.</p>

  <% if @last_payment %>
      <%= render Settings::ControlGroupComponent.new class: "mb-4" do |group| %>
        <% group.item do %>
          <%= check_box_tag :billing_event_id, Rails.application.message_verifier(:billing_event_id).generate(@last_payment.id), false, class: "peer" %>
          <%= label_tag :billing_event_id, class: "group" do %>
            <%= render Settings::ControlRowComponent.new do |row| %>
              <% row.title do %>
                Also refund my recent <strong><%= number_to_currency((@last_payment.event_object["amount"].to_f / 100), precision: 0) %></strong> payment
              <% end %>
              <% row.control { render Form::SwitchComponent.new } %>
            <% end %>
          <% end %>
        <% end %>
      <% end %>
  <% end %>

  <%= render Settings::ButtonRowComponent.new do %>
    <%= f.submit "Cancel Account", class: "button button-secondary", data: { confirm: "Are you sure?" } %>
  <% end %>
<% end %>